package com.waterdrop.wlsggk.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.waterdrop.wlsggk.pojo.TransferResidue;
import com.waterdrop.wlsggk.service.ITransferResidueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 中转仓库剩余Controller
 *
 * @author Naruto
 * @date 2023-10-23
 */
@RestController
@RequestMapping("/wlsggk/residue")
public class TransferResidueController extends BaseController {
    @Autowired
    private ITransferResidueService transferResidueService;

    /**
     * 查询中转仓库剩余列表
     */
    @PreAuthorize("@ss.hasPermi('wlsggk:residue:list')")
    @GetMapping("/list")
    public TableDataInfo list(TransferResidue transferResidue) {
        startPage();
        List<TransferResidue> list = transferResidueService.selectTransferResidueList(transferResidue);
        return getDataTable(list);
    }

    /**
     * 导出中转仓库剩余列表
     */
    @PreAuthorize("@ss.hasPermi('wlsggk:residue:export')")
    @Log(title = "中转仓库剩余", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TransferResidue transferResidue) {
        List<TransferResidue> list = transferResidueService.selectTransferResidueList(transferResidue);
        ExcelUtil<TransferResidue> util = new ExcelUtil<TransferResidue>(TransferResidue.class);
        util.exportExcel(response, list, "中转仓库剩余数据");
    }

    /**
     * 获取中转仓库剩余详细信息
     */
    @PreAuthorize("@ss.hasPermi('wlsggk:residue:query')")
    @GetMapping(value = "/{residueId}")
    public AjaxResult getInfo(@PathVariable("residueId") Long residueId) {
        return success(transferResidueService.selectTransferResidueByResidueId(residueId));
    }

    /**
     * 新增中转仓库剩余
     */
    @PreAuthorize("@ss.hasPermi('wlsggk:residue:add')")
    @Log(title = "中转仓库剩余", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TransferResidue transferResidue) {
        return toAjax(transferResidueService.insertTransferResidue(transferResidue));
    }

    /**
     * 修改中转仓库剩余
     */
    @PreAuthorize("@ss.hasPermi('wlsggk:residue:edit')")
    @Log(title = "中转仓库剩余", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TransferResidue transferResidue) {
        return toAjax(transferResidueService.updateTransferResidue(transferResidue));
    }

    /**
     * 删除中转仓库剩余
     */
    @PreAuthorize("@ss.hasPermi('wlsggk:residue:remove')")
    @Log(title = "中转仓库剩余", businessType = BusinessType.DELETE)
    @DeleteMapping("/{residueIds}")
    public AjaxResult remove(@PathVariable Long[] residueIds) {
        return toAjax(transferResidueService.deleteTransferResidueByResidueIds(residueIds));
    }
}
